package Handler;
import dao.ISupplierDao;
import dao.impl.SupplierDaoImpl;
import pojo.Supplier;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

public class SupplierHandler {
    public void addSupplier(HttpServletRequest request, HttpServletResponse response) {
        try {

            String name=request.getParameter("name");
            ISupplierDao supplierDao=new SupplierDaoImpl();
            supplierDao.addSupplier(name);
            showSupplier(request,response);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public void showSupplier(HttpServletRequest request, HttpServletResponse response){
        try {
            ISupplierDao supplierDao=new SupplierDaoImpl();
            List<Supplier> suppliers=supplierDao.findAll();
            request.getSession().setAttribute("suppliers",suppliers);
            request.getRequestDispatcher("/admin/supplierList.jsp").forward(request,response);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
